package com.binance.zkconfig.app.model;

import com.netflix.config.PropertyWrapper;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by Fei.Huang on 2018/8/31.
 * <p>
 * key:value#description (适配类似PNK中SysConfig需求)
 */
public class DynamicStringDescProperty extends PropertyWrapper<String> {

    private static final String POUND = "#";

    public DynamicStringDescProperty(String propName, String defaultValue) {
        super(propName, defaultValue);
    }

    public String get() {
        return prop.getString(defaultValue);
    }

    @Override
    public String getValue() {
        String value = get();
        if (StringUtils.isNotBlank(value) && value.contains(POUND)) {
            String[] values = value.split(POUND);
            value = values[0];
        }
        return value;
    }

    public String getDescription() {
        String value = get();
        if (StringUtils.isNotBlank(value) && value.contains(POUND)) {
            String[] values = value.split(POUND);
            value = values[1];
            return value;
        } else {
            return StringUtils.EMPTY;
        }
    }
}
